<?php

namespace App\Http\Controllers;

use Illuminate\Http\File;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;

class ArticleController extends Controller
{

    //显示添加文章
    public function create()
    {
        return view('article.create');

    }

    //保存文章
    public function store()
    {
        $data = request()->input();
        dd($data);
    }

    //文件上传
    public function fileCommand()
    {
        //保存文件到本地磁盘上
        //注意不写disk则默认保存到本地磁盘系统
        //Storage::disk('local')->put('file.txt','content');
        //获取文件内容
        $contents = Storage::get('file.txt');
//        dd($contents);
        //判断磁盘上是否存在文件
        $exists = Storage::exists('file.txt');
//        dd($exists);
        $url = Storage::url('file.txt');
        echo $url.'<br>';
        //获取文件信息
        $size = Storage::size('file.txt');
        echo $size;
        //流式传输，返回文件所在路径
        //$path = Storage::putFile('photos',new File('file.txt'));
        //向文件前追加内容
//        Storage::prepend('file.txt','prepended text');
//        //向文件后追加内容
//        Storage::append('file.txt','appended text');
//        //复制文件
//        Storage::copy('file.txt','new/file.txt');
//        //移动文件
//        Storage::move('file.txt','old/file.txt');

        //文件的可见性操作
        Storage::put('file.txt',$contents, 'public');
        Storage::getVisibility('file.txt');
        Storage::setVisibility('file.txt', 'public');

        //删除文件
        Storage::delete('file.txt');
        Storage::delete(['file.txt','file1.txt']);

        $directory = '/';
        //目录操作
        //获取目录中的所有文件
        $files = Storage::files($directory);
        //获取目录及子目录下的所有文件
        $files = Storage::files($directory);

        //获取目录下的所有目录
        $directories = Storage::directories($directory);
        //获取目录及子目录下的所有目录
        Storage::allDirectories($directory);

        //创建目录
        Storage::makeDirectory($directory);

        //删除目录
        Storage::deleteDirectory($directory);


    }


}
